package com.zhss.eshop.schedule.mapper;

import com.zhss.eshop.schedule.domain.model.ScheduleGoodsAllocationStockDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ScheduleGoodsAllocationStockDetailMapper {
    int deleteByPrimaryKey(Long id);

    int insertSelective(ScheduleGoodsAllocationStockDetail record);

    ScheduleGoodsAllocationStockDetail selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(ScheduleGoodsAllocationStockDetail record);

    /**
     * 根据商品sku id查询货位库存明细
     * @param goodsSkuId 商品sku id
     * @return 货位库存明细
     */
    @Select("SELECT "
            + "id,"
            + "goods_sku_id,"
            + "goods_allocation_id,"
            + "put_on_time,"
            + "put_on_quantity,"
            + "current_stock_quantity,"
            + "locked_stock_quantity,"
            + "gmt_create,"
            + "gmt_modified "
            + "FROM schedule_goods_allocation_stock_detail "
            + "WHERE goods_sku_id=#{goodsSkuId} "
            + "AND current_stock_quantity>0 "
            + "ORDER BY put_on_time")
    @Results({
            @Result(column = "id", property = "id", id = true),
            @Result(column = "goods_sku_id", property = "goodsSkuId"),
            @Result(column = "goods_allocation_id", property = "goodsAllocationId"),
            @Result(column = "put_on_time", property = "putOnTime"),
            @Result(column = "put_on_quantity", property = "putOnQuantity"),
            @Result(column = "current_stock_quantity", property = "currentStockQuantity"),
            @Result(column = "locked_stock_quantity", property = "lockedStockQuantity"),
            @Result(column = "gmt_create", property = "gmtCreate"),
            @Result(column = "gmt_modified", property = "gmtModified")
    })
    List<ScheduleGoodsAllocationStockDetail> listByGoodsSkuId(
            @Param("goodsSkuId") Long goodsSkuId);
}
